#!/usr/bin/perl
use warnings;
use strict;
require 'doctorIO.pl';
my $flag = shift @ARGV;
my $doctxt = "doctors.txt";
my $typtxt = "types.txt";
#add doctor flag
if ($flag eq "-ad"){
	my ($name, $type, $start, $end) = @ARGV;
	if (not get_doctor($name)){
		echo($doctxt, "$name,$type,$start,$end");
		alog("Doctor $name added successfully.");
	}
	else {
		alog("Doctor $name already exists.");
	}
}
#del doctor
elsif ($flag eq "-dd"){
	my $doctor = $ARGV[0];
	open(IN, "<", $doctxt);
	my @lines = grep !/$doctor,/, <IN>;
	close(IN);
	open(OUT, ">", $doctxt);
	print OUT @lines;
	close(OUT);
	alog("Doctor $doctor deleted.");
}
#add type
elsif ($flag eq "-at"){
	my $type = $ARGV[0];
	if (not is_type($type)){
		echo($typtxt, $type);
		alog("Type $type added successfully.");
	}
	else {
		alog("Type $type already exists.");
	}
}
#del type
elsif ($flag eq "-dt"){
	my $type = $ARGV[0];
	open(IN, "<", $typtxt);
	my @lines = grep !/$type/, <IN>;
	close(IN);
	open(OUT, ">", $typtxt);
	print OUT @lines;
	close(OUT);
	alog("Type $type deleted.");
}
